package com.example.demo.config;

import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName RedisConfig
 * @Author bsy
 * @Description TODO
 * @Date 2022/1/9 15:36
 * @Version 1.0
 */

@Configuration
public class RedisConfig {

    @Value("${config.redis.host}")
    private String host;
    @Value("${config.redis.port}")
    private String port;

    @Value("${config.redis.password}")
    private String password;

    @Bean
    public Redisson redisson() {
        // 此为单机模式
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://"+host+":"+port)
                .setPassword(password)
                .setDatabase(1);
        return (Redisson) Redisson.create(config);
    }


}
